/*
 * frmAgregarJugadores2.java
 *
 * Created on 9 de septiembre de 2007, 11:03 PM
 */

package prototipo;
import BE.division;
import BE.torneo;

import BL.divisionBL;
import BL.torneoBL;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Vector;
import java.util.regex.PatternSyntaxException;
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableRowSorter;
import ajedrezLogica.frmIngresoPartidas;
import ajedrezLogica.frmLecturaPartidas;

/**
 *
 * @author  Billy
 */
public class frmElegirTorneo extends javax.swing.JInternalFrame {
    
    torneo unTorneo;
    DefaultTableModel dtm;
    TableRowSorter sorter;
    String text;
    ArrayList<division> lstDiv; /*Madrugada del lunes 08 de octubre del 2007. 12:55am*/
    ArrayList<division> localArrdivBL;
    divisionBL divBL;
    
    frmIngresoPartidas fip;
    frmBuscarPartidas fbp;
    frmLecturaPartidas flp;
    
    int codDivision, fila;
    
    ArrayList <torneo> arrtBL;
    torneoBL tBL;
    String tipo = "";
    /** Creates new form frmAgregarJugadores2 */
    public frmElegirTorneo(frmIngresoPartidas fip) {
        this.tareaPrevia();                
        this.fip = fip;
        this.tipo = "fip";        
    }
    
    public frmElegirTorneo(frmBuscarPartidas fbp) {
        this.tareaPrevia();
        this.fbp = fbp;
        this.tipo = "fbp";        
    }
    
    public frmElegirTorneo(frmLecturaPartidas flp) {
        this.tareaPrevia();
        this.flp = flp;
        this.tipo = "flp";        
    }    
    public void tareaPrevia(){
        initComponents();
        tBL = new torneoBL();
        this.txtFiltro.getDocument().addDocumentListener(new DocumentListener() {
            public void insertUpdate(DocumentEvent evt) {
                searchFieldChangedUpdate(evt);
            }
            public void removeUpdate(DocumentEvent evt) {
                searchFieldChangedUpdate(evt);
            }
            public void changedUpdate(DocumentEvent evt) {
                searchFieldChangedUpdate(evt);
            }
        });  
        this.llenarGrillaTorneos();
        /**/
        this.btnActualizarJugador.setEnabled(false);        
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jPanel1 = new javax.swing.JPanel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblTorneos = new javax.swing.JTable();
        jLabel9 = new javax.swing.JLabel();
        txtFiltro = new javax.swing.JTextField();
        pnlInscripcion = new javax.swing.JPanel();
        btnElegirJugador = new javax.swing.JButton();
        btnActualizarDatos = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        txtNombreTorneo = new javax.swing.JTextField();
        txtCiudad = new javax.swing.JTextField();
        txtOrganizador = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jdcFechaFin = new com.toedter.calendar.JDateChooser();
        jLabel8 = new javax.swing.JLabel();
        btnActualizarJugador = new javax.swing.JButton();
        btnLimpiar = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jdcFechaInicio = new com.toedter.calendar.JDateChooser();
        btnNuevoTorneo = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();

        setClosable(true);
        setIconifiable(true);
        setTitle("Elegir Torneo");
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        tblTorneos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Cod", "Nombre de torneo", "fecha Inicio", "fecha Final"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        tblTorneos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblTorneosMouseClicked(evt);
            }
        });

        jScrollPane2.setViewportView(tblTorneos);

        jLabel9.setText("Torneo a Buscar");

        pnlInscripcion.setBorder(javax.swing.BorderFactory.createTitledBorder("Elegir Jugador"));
        btnElegirJugador.setText("Elegir Torneo");
        btnElegirJugador.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnElegirJugadorActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnlInscripcionLayout = new javax.swing.GroupLayout(pnlInscripcion);
        pnlInscripcion.setLayout(pnlInscripcionLayout);
        pnlInscripcionLayout.setHorizontalGroup(
            pnlInscripcionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlInscripcionLayout.createSequentialGroup()
                .addContainerGap(28, Short.MAX_VALUE)
                .addComponent(btnElegirJugador)
                .addGap(21, 21, 21))
        );
        pnlInscripcionLayout.setVerticalGroup(
            pnlInscripcionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlInscripcionLayout.createSequentialGroup()
                .addComponent(btnElegirJugador)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        btnActualizarDatos.setText("Actualizar datos");
        btnActualizarDatos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnActualizarDatosActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(jLabel9)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtFiltro, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 149, Short.MAX_VALUE)
                                .addComponent(btnActualizarDatos))
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 470, Short.MAX_VALUE)))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(144, 144, 144)
                        .addComponent(pnlInscripcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(txtFiltro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnActualizarDatos, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(14, 14, 14)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 155, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlInscripcion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(89, 89, 89))
        );
        jTabbedPane1.addTab("Elegir Torneo", jPanel3);

        jLabel1.setText("Nombre Torneo:");

        jLabel2.setText("Ciudad:");

        jLabel3.setText("Organizador:");

        jLabel5.setText("Fecha de Inicio :");

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/prototipo/mod_jugador.jpg")));

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel6)
        );

        jLabel8.setText("Fecha Final: ");

        btnActualizarJugador.setText("Actualizar datos");
        btnActualizarJugador.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnActualizarJugadorActionPerformed(evt);
            }
        });

        btnLimpiar.setText("Limpiar");
        btnLimpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimpiarActionPerformed(evt);
            }
        });

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel7.setText("(*)");

        jLabel12.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel12.setText("(*)");

        jLabel15.setText("Datos Obligatorios");

        jLabel14.setFont(new java.awt.Font("Tahoma", 1, 11));
        jLabel14.setText("(*)");

        btnNuevoTorneo.setText("Crear Nuevo Torneo");
        btnNuevoTorneo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNuevoTorneoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel5)
                            .addComponent(jLabel8))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 55, Short.MAX_VALUE)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jdcFechaInicio, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jdcFechaFin, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(txtOrganizador, javax.swing.GroupLayout.DEFAULT_SIZE, 146, Short.MAX_VALUE)
                            .addComponent(txtCiudad)
                            .addComponent(txtNombreTorneo, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addComponent(jLabel12))
                        .addGap(55, 55, 55)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jLabel14)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel15))
                            .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 470, Short.MAX_VALUE)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(btnLimpiar)
                        .addGap(71, 71, 71)
                        .addComponent(btnNuevoTorneo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 88, Short.MAX_VALUE)
                        .addComponent(btnActualizarJugador)))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel4Layout.createSequentialGroup()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel12)
                                .addComponent(txtNombreTorneo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(txtCiudad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jLabel7)
                            .addComponent(txtOrganizador, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(29, 29, 29)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addGap(15, 15, 15)
                                .addComponent(jLabel8))
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addComponent(jdcFechaInicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jdcFechaFin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel4Layout.createSequentialGroup()
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(15, 15, 15)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel14)
                            .addComponent(jLabel15))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 47, Short.MAX_VALUE)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnLimpiar)
                    .addComponent(btnActualizarJugador)
                    .addComponent(btnNuevoTorneo))
                .addGap(33, 33, 33))
        );
        jTabbedPane1.addTab("Ingresar Nuevo Torneo", jPanel4);

        jButton1.setText("Salir");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 495, Short.MAX_VALUE)
                    .addComponent(jButton1))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 320, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    private void btnNuevoTorneoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNuevoTorneoActionPerformed
// TODO add your handling code here:
        unTorneo = new torneo();
        unTorneo.setnombreTorneo(txtNombreTorneo.getText());
        unTorneo.setCiudad(txtCiudad.getText());
        unTorneo.setOrganizador(txtOrganizador.getText());
        unTorneo.setFechaInicio(this.jdcFechaInicio.getCalendar());
        unTorneo.setFechaFin(this.jdcFechaFin.getCalendar());
        unTorneo.setNumeroDivisiones(0);
        unTorneo.setTerminoTorneo(false);
        
        if(this.txtNombreTorneo.getText().trim().length()==0){
            JOptionPane.showMessageDialog(this,"Ponga el Nombre del Torneo, Por favor","Informacion",JOptionPane.WARNING_MESSAGE);
        } else if(this.txtOrganizador.getText().trim().length()==0){
            JOptionPane.showMessageDialog(this,"Ponga el Nombre del Organizador, Por favor","Informacion",JOptionPane.WARNING_MESSAGE);
        } else{
            torneoBL admTorneoBL = new torneoBL();
            if(admTorneoBL.crear(unTorneo))
                JOptionPane.showMessageDialog(this,"Los datos han sido guardados correctamente","Informacion",JOptionPane.INFORMATION_MESSAGE);
            else
                JOptionPane.showMessageDialog(this,"Ha Ocurrido un error. No se han grabado los datos","Informacion",JOptionPane.INFORMATION_MESSAGE);
            this.llenarGrillaTorneos();
            this.limpiarDatos();
            //this.fmi2.llenarGrillaTorneos();
            //this.dispose();
        }
        
        
    }//GEN-LAST:event_btnNuevoTorneoActionPerformed
    
    private void btnElegirJugadorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnElegirJugadorActionPerformed
// TODO add your handling code here:
        
        int fila, id;
        int indiceTablaOrdenada;
        
        fila= this.tblTorneos.getSelectedRow();
        if(fila >= 0){
            indiceTablaOrdenada = tblTorneos.convertRowIndexToModel(fila);
            unTorneo = this.arrtBL.get( /*fila*/ indiceTablaOrdenada);
        }
        if(tipo.equals("fip")==true) this.fip.dameTorneo(unTorneo);        
        else if(tipo.equals("fbp")==true) this.fbp.dameTorneo(unTorneo);        
        else this.flp.dameTorneo(unTorneo);
        this.dispose();
    }//GEN-LAST:event_btnElegirJugadorActionPerformed
    
    private void btnLimpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimpiarActionPerformed
// TODO add your handling code here:
        this.limpiarDatos();
    }//GEN-LAST:event_btnLimpiarActionPerformed
    
    private void btnActualizarJugadorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnActualizarJugadorActionPerformed
// TODO add your handling code here:
        boolean resultado = false;
        //System.out.print("AAA: "+ this.txtApellidoPaterno.getText().length());
        int elegido = 0;
        unTorneo.setnombreTorneo(this.txtNombreTorneo.getText());
        unTorneo.setCiudad(this.txtCiudad.getText());
        unTorneo.setOrganizador(this.txtOrganizador.getText());
        unTorneo.setFechaInicio(this.jdcFechaInicio.getCalendar());
        unTorneo.setFechaFin(this.jdcFechaFin.getCalendar());
        
        if(this.txtNombreTorneo.getText().trim().length()==0){
            JOptionPane.showMessageDialog(this,"Ponga el nombre del Torneo, Por favor","Informacion",JOptionPane.WARNING_MESSAGE);
        } else{
            resultado = tBL.actualizarTorneo(unTorneo.getIdTorneo(), unTorneo);
            
            if(resultado == true){
                JOptionPane.showMessageDialog(this,"Se ha actualizado correctamente","Informacion",JOptionPane.INFORMATION_MESSAGE);
            } else{
                JOptionPane.showMessageDialog(this,"Ha Ocurrido un error. No se han grabado los datos","Informacion",JOptionPane.INFORMATION_MESSAGE);
            }
            this.limpiarDatos();
            llenarGrillaTorneos();
        }
        
    }//GEN-LAST:event_btnActualizarJugadorActionPerformed
    public void editarDatosTorneo(int indice){
    
    }
    private void btnActualizarDatosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnActualizarDatosActionPerformed
// TODO add your handling code here:
        int fila, id;
        int indiceTablaOrdenada;
        jTabbedPane1.setSelectedIndex(1);
        
        fila= this.tblTorneos.getSelectedRow();
        if(fila >= 0){
            indiceTablaOrdenada = tblTorneos.convertRowIndexToModel(fila);
            
            unTorneo = this.arrtBL.get(indiceTablaOrdenada);
            
            this.txtNombreTorneo.setText(unTorneo.getnombreTorneo().toString());
            this.txtCiudad.setText(unTorneo.getCiudad().toString());
            this.txtOrganizador.setText(unTorneo.getOrganizador().toString());
            this.jdcFechaInicio.setCalendar(unTorneo.getFechaInicio());
            this.jdcFechaFin.setCalendar(unTorneo.getFechaFin());
            /**/
            this.btnActualizarJugador.setEnabled(true);
        }
    }//GEN-LAST:event_btnActualizarDatosActionPerformed
    
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed
    
    private void tblTorneosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblTorneosMouseClicked
// TODO add your handling code here:
        fila= this.tblTorneos.getSelectedRow();
        unTorneo = this.arrtBL.get(fila);
        
    }//GEN-LAST:event_tblTorneosMouseClicked
    
    
    private void searchFieldChangedUpdate(DocumentEvent evt) {
        try {
            text = this.txtFiltro.getText();
            if (text.length() == 0) {
                sorter.setRowFilter(null);
            } else {
                try{
                    sorter.setRowFilter(RowFilter.regexFilter("(?i)"+text));
                }catch(PatternSyntaxException e) {
                    e.printStackTrace();
                }
            }
        }catch(Exception e) {
            e.printStackTrace();
        }
    }
    void limpiarDatos(){
        this.txtCiudad.setText("");
        this.txtNombreTorneo.setText("");
        this.txtOrganizador.setText("");
    }
    public JTabbedPane damePaneldePestanas(){
        return  this.jTabbedPane1;
    }
    
    public void llenarGrillaTorneos() {
        int ano, ano2, mes, mes2, dia, dia2;
        arrtBL = new ArrayList<torneo>();
        
        Vector rows = new Vector();
        
        for( torneo tBE : this.tBL.getLstTorneos()){
            arrtBL.add(tBE);
            Vector row = new Vector();
            row.add(tBE.getIdTorneo());
            row.add(tBE.getnombreTorneo());
            
            ano = tBE.getFechaInicio().get(Calendar.YEAR);
            mes = tBE.getFechaInicio().get(Calendar.MONTH)+1;
            dia = tBE.getFechaInicio().get(Calendar.DATE);
            row.add(ano+"/"+mes+"/"+dia);
            
            ano2 = tBE.getFechaFin().get(Calendar.YEAR);
            mes2 = tBE.getFechaFin().get(Calendar.MONTH)+1;
            dia2 = tBE.getFechaFin().get(Calendar.DATE);
            row.add(ano2+"/"+mes2+"/"+dia2);
            
            rows.add(row);
        }
        
        Vector colNames = new Vector();
        for (int i=0;i<this.tblTorneos.getColumnCount();i++){
            colNames.add(this.tblTorneos.getColumnName(i));
        }
        
//        dtm = new DefaultTableModel(rows,colNames);
        dtm = new DefaultTableModel(rows,colNames) {
//            public Class getColumnClass(int col){
//                switch (col) {
//                    case 4: return Boolean.class;
//                    default: return Object.class;
//                }
//            }
            public boolean isCellEditable(int row, int column) {
                //return column == 4;
                return false;
            }
        };
        
        sorter = new TableRowSorter(dtm);
//        sorter.setRowFilter(RowFilter.regexFilter(text);
        this.tblTorneos.setModel(dtm);
        this.tblTorneos.setRowSorter(sorter);
        
        TableColumnModel tcm = tblTorneos.getColumnModel();
        tcm.getColumn(0).setPreferredWidth(20);
        tcm.getColumn(1).setPreferredWidth(100);
//        tcm.getColumn(4).setPreferredWidth(20);
    }
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnActualizarDatos;
    private javax.swing.JButton btnActualizarJugador;
    private javax.swing.JButton btnElegirJugador;
    private javax.swing.JButton btnLimpiar;
    private javax.swing.JButton btnNuevoTorneo;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private com.toedter.calendar.JDateChooser jdcFechaFin;
    private com.toedter.calendar.JDateChooser jdcFechaInicio;
    private javax.swing.JPanel pnlInscripcion;
    private javax.swing.JTable tblTorneos;
    private javax.swing.JTextField txtCiudad;
    private javax.swing.JTextField txtFiltro;
    private javax.swing.JTextField txtNombreTorneo;
    private javax.swing.JTextField txtOrganizador;
    // End of variables declaration//GEN-END:variables
    
}
